﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using DataAccessEntLib;

public partial class SideAdControl : System.Web.UI.UserControl
{
    BO.Ad bo = new BO.Ad();
    BLL.AdMagnager bll = new BLL.AdMagnager();

    protected void Page_Load(object sender, EventArgs e)
    {        
        if (!IsPostBack)
        {
            int CountryID = 0;
            if (!object.Equals(Request.Cookies["countryid"], null))
            {
                HttpCookie myCookie = Request.Cookies.Get("countryid");
                Response.Cookies.Add(myCookie);
                if (myCookie.Value != string.Empty)
                {
                    CountryID = Convert.ToInt32(myCookie.Value);
                }
            }
            BindRightAD(CountryID);
        }
       
    }

    protected void BindRightAD(int CountryID)
    {
        if (CountryID > 0)
        {
            IDataReader dr;
            bo.CountryID = CountryID;
            dr = bll.SelectRightAd(bo);
            if (dr != null)
            {
                //divRightAd.InnerHtml = "<h1><img src='images/popular_icon.png' height='24' width='24' border='0' align='absmiddle'><span class='ml5px'>Popular Items</span></h1>";
                while (dr.Read())
                {
                    divRightAd.InnerHtml += "<div class='pb0px refine_search_box'><img src='" + dr["ImagePath"].ToString() + "' height='138' width='131' border='0'  align='left' /><h3 style='font-weight:bold;font-size:14px;'><a href='Cld-Ad-Details.aspx?AdID=" + dr["AdID"].ToString() + "' style='color:#666'>" + dr["AdTitle"].ToString() + "</a></h3><p class='txcenter'>" + dr["ProductDescription"].ToString() + "</p></div>";
                }
                divRightAd.InnerHtml += "";
            }
            dr.Close();
        }
    }
}